from collections import OrderedDict

from django.http import HttpResponse
from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from User.models import SiteUser


class withUserModelViewSet(ModelViewSet):
    """
    withUserModelSetView 可以 request的用户传给具体的序列器
    """

    def get_serializer_context(self):
        context = super().get_serializer_context()
        context_dict = {'request': self.request}

        user = self.request.user

        if user:
            context_dict["user"] = user
        context.update(context_dict)
        return context


class ManagerOwnerViewSet(ModelViewSet):
    """
    如果要使用权限类`ManagerOwner`就需要继承该类， 更多用法查看权限类 `ManagerOwner`
    """

    def get_obj_user(self, obj) -> SiteUser:
        """
        获取queryset中user的方法
        """
        return ...
